package com.heima.scan.listener;

import com.heima.common.constants.KafkaMessageConstants;
import com.heima.scan.dao.WmNewsDao;


import com.heima.scan.service.WmNewsAutoScanService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


@Component
@Slf4j
class KafkaAutoListener {
    @Resource
    private WmNewsAutoScanService wmNewsAutoScanService;

    @KafkaListener(topics=KafkaMessageConstants.WM_NEWS_AUTO_SCAN_TOPIC,groupId = "WM_NEWS_AUTO_SCAN")
    public void AutoScanNewsListener(ConsumerRecord<String,String> record){
           log.info("文章ID:{}",record.value());
        Long newsId = Long.valueOf(record.value());
        if (newsId!=null) {
            wmNewsAutoScanService.autoScanNews(newsId);
        }
        log.info("执行完毕!");
    }

}
